/**
 * Programmiertechniken 1 /GDI
 * File: CReadUtil.java
 * @author Manh Tien Tran
 * @version 1.0
 * This class implements simple methods to read data of simple types from
 * the terminal. You can type several numbers at once. For example you
 * can write
 * <code>
 *     System.out.print("Geben Sie zwei Zahlen ein: ");
 *     System.out.flush();
 *     int a = CReadUtil.nextInt();
 *     int b = CReadUtil.nextInt();
 * </code>
 * Also you can write
 * <code>
 *     int a = CReadUtil.nextInt("Geben Sie eine Zahl ein ");
 * </code>
 */
package util;

import java.util.*;
import java.io.*;
import static java.lang.System.out;


public class CReadUtil
{
   /**
   *  we use sIn  for reading the inpt data 
   */
   private static Scanner sIn
            = new Scanner(System.in);
 

   public static void init(String filename) throws FileNotFoundException
   {
  	 sIn.close();
  	 sIn = new Scanner(new FileReader(filename));

   }
   
   /**
    * get a whole line as String from the console
    * @param prompt prompt to write out before reading the next line
    * @return the text line
    */
    public static String nextLine(String prompt)
    {
    	out.print(prompt);
	return sIn.nextLine();
    }  // end of getLine


   /**
   * get a whole line as String from the console
   * @return the text line
   */
   public static String nextLine()
   {
       return sIn.nextLine();
   }  // end of getLine



   /**
   * read a boolean from the console.
   * @param thePrompt prompt to write out before reading the boolean value
   * @return true if the string true is the input, false else
   * @see java.util.Scanner
   */
   public static boolean nextBoolean(String thePrompt)  throws InputMismatchException
   {
      out.print(thePrompt);
      return sIn.nextBoolean();
   }  // end of nextBoolean


   /**
   * read a boolean from the console
   * @return true if the string true is the input, false else
   * @see java.util.Scanner
   */
   public static boolean nextBoolean() throws InputMismatchException
   {
      return sIn.nextBoolean();
   }  // end of nextBoolean



   /**
   * read a byte value from the console.
   * @param thePrompt prompt to write out before reading a byte value
   * @return the corresponding byte value
   * @see java.util.Scanner
   */
   public static byte nextByte(String thePrompt)  throws InputMismatchException
   {
      out.print(thePrompt);
      return sIn.nextByte();
   }  // end of nextByte


   /**
   * read a byte value from the console.
   * @return the corresponding byte value
   * @see java.util.Scanner
   */
   public static byte nextByte()  throws InputMismatchException
   {
      return sIn.nextByte();
   }  // end of nextByte


   /**
   * read a short value from the console
   * @param thePrompt prompt to write out before reading a short value
   * @return the corresponding short value
   * @see java.util.Scanner
   */
   public static short nextShort(String thePrompt)  throws InputMismatchException
   {
      out.print(thePrompt);
      return sIn.nextShort();
   }  // end of nextShort

   /**
   * read a short value from the console.
   * @return the corresponding short value
   * @see java.util.Scanner
   */
   public static short nextShort()  throws InputMismatchException
   {
      return sIn.nextShort();
   }  // end of nextShort


   /**
   * read a integer value from the console.
   * @param thePrompt string to write out before reading a int value
   * @return the corresponding integer value
   * @see java.util.Scanner
   */
   public static int nextInt(String thePrompt)  throws InputMismatchException
   {
      out.print(thePrompt);
      return sIn.nextInt();
   }  // end of nextInt


   /**
   * read a integer value from the console.
   * @return the corresponding integer value
   * @see java.util.Scanner
   */
   public static int nextInt()  throws InputMismatchException
   {
      return sIn.nextInt();
   }  // end of nextInt


   /**
   * read a long value from the console.
   * @param thePrompt pompt to write out before reading the value
   * @return the corresponding long value
   * @see java.util.Scanner	
   */
   public static long nextLong(String thePrompt)  throws InputMismatchException
   {
      out.print(thePrompt);
      return sIn.nextLong();
   }  // end of nextLong


   /**
   * read a long value from the console.
   * @return the corresponding long value
   * @see java.util.Scanner
   */
   public static long nextLong()  throws InputMismatchException
   {
      return sIn.nextLong();
   }  // end of nextLong

   /**
   * read a float value from the console.
   * @param thePrompt prompt to write out before reading the value
   * @return the corresponding float value
   * @see java.util.Scanner
   */
   public static float nextFloat(String thePrompt)  throws InputMismatchException
   {
      System.out.print(thePrompt);
      return sIn.nextFloat();
   }  // end of nextFloat


   /**
   * read a float value from the console.
   * @return the corresponding float value
   * @see java.util.Scanner
   */
   public static float nextFloat()  throws InputMismatchException
   {
      return sIn.nextFloat();
   }  // end of nextFloat


   /**
   * read a double value from the console.
   * @param thePrompt prompt to write out before reading the value
   * @return the corresponding double value
   * @see java.util.Scanner
   */
   public static double nextDouble(String thePrompt)  throws InputMismatchException
   {
      System.out.print(thePrompt);
      return sIn.nextDouble();
   }  // end of nextDouble


   /**
   * read a double value from the console
   * @return the corresponding double value
   * @see java.util.Scanner
   */
   public static double nextDouble()  throws InputMismatchException
   {
      return sIn.nextDouble();
   }  // end of nextDouble


   /**
   * read a string from the console.
   * @param thePrompt prompt to write out before reading the value
   * @return the corresponding string
   */
   public static String nextString(String thePrompt)
   {
      out.print(thePrompt);
      return sIn.next();
   }  // end of nextString



   /**
   * read a string from the console.
   * @return the corresponding string
   */
   public static String nextString()
   {
	   if (sIn.hasNext())
		   return sIn.next();
	   else return null;
   }  // end of readString

 

}  // end of CReadUtil
